import { languageModelUsing } from "@/services/languageModel";
import { Modal, Table } from "antd";
import moment from "moment";
import React from "react";

class UsingModelList extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
      list: []
    }
  }

  componentDidMount() {
    if (this.props.onRef) {
      this.props.onRef(this)
    }
  }

  initModal = (modelId) => {
    this.setState({ visible: true, loading: true }, async () => {
      const res = await languageModelUsing({ modelId })
      this.setState({ list: res, loading: false })
    })
  }

  render() {
    const { visible, list, loading } = this.state;
    const columns = [
      {
        title: "应用名称",
        dataIndex: "applicationName",
        width: 200
      },
      {
        title: "应用类型",
        dataIndex: "applicationPlatform",
        width: 150,
        render: type => {
          let name = ''
          switch (type) {
            case 'QWX_NATIVE':
              name = '企微原生';
              break;
            case 'QWX_CORP_BUILD':
              name = '企微自建';
              break;
            case 'DD_NATIVE':
              name = '钉钉原生';
              break;
            case 'DD_CORP_BUILD':
              name = '钉钉自建';
              break;
            case 'FS_CORP_BUILD':
              name = '飞书自建';
              break;
            case 'FS_NATIVE':
              name = '飞书原生';
              break;
            case 'PURE_WEB':
              name = '网页版';
              break;
            case 'DIGITAL_SCREEN':
              name = '数字人大屏';
              break;
            case 'SYS_WEB':
              name = '默认应用'
              break;
            default:
              name = '网页版';
              break;
          };

          return name;
        }
      },
      {
        title: "生效时间",
        dataIndex: "useTime",
        width: 150,
        render: time => {
          return time ? moment(time).format("YYYY-MM-DD HH:mm:ss") : ''
        }
      },
    ];

    return (
      <Modal title="模型使用情况" visible={visible} footer={null} onCancel={() => this.setState({ visible: false, list: [] })} width={700}>
        <div style={{ padding: '0 10px', borderLeft: '2px solid #3f4959', marginBottom: 24, color: '#000' }}>正在使用该模型的应用</div>
        <Table columns={columns} dataSource={list} loading={loading} rowKey={(index) => index} />
      </Modal>
    )
  }
}

export default UsingModelList